package cloud.dandanit.itservice.controller.image;


import cloud.dandanit.itservice.entity.Image;
import cloud.dandanit.itservice.service.ImageService;
import cloud.dandanit.itservice.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author luokai
 * @since 2022-07-04
 */
@SuppressWarnings({"unchecked", "DuplicatedCode"})
@RestController
@RequestMapping("/itservice/imagefront")
public class ImageFrontController {

    @Autowired
    private ImageService imageService;

    /**
     * 获取前台首页图片方法
     * @return 图片列表
     */
    @GetMapping("getIndexImage")
    @ApiOperation("获取首页图片接口")
    public R getIndexImage() {

        List<Image> imageList = imageService.getIndexImage();
        return R.ok().data("imageList", imageList);
    }

    @ApiOperation(value = "前台获取图片分页列表")
    @GetMapping("pageImage/{page}/{limit}")
    public R getPageImage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit) {

        Page<Image> pageParam = new Page<>(page, limit);
        LambdaQueryWrapper<Image> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Image::getState,1)
                    .orderByDesc(Image::getSort);
        imageService.page(pageParam,queryWrapper);
        return R.ok().data("items", pageParam.getRecords()).data("total", pageParam.getTotal());
    }

}

